package com.jason.quectel0805.adapters;

import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

/**
 * @author：Jason
 * @date：2022/8/9 14:25
 * @email：1129847330@qq.com
 * @description:
 */
public class MyViewPagerAdapter extends PagerAdapter {
    //数据源
    private List<View> list = new ArrayList<>();

    public MyViewPagerAdapter(List<View> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = list.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(list.get(position));
    }

    //用于viewpager数据刷新时使用
    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_NONE;
    }
}